<template>
	<view style="width: 100%;padding: 20rpx;">
		<view class="" style="margin-top: 50rpx;">
			<u-form :model="form" ref="uForm">
				<u-form-item label-width="150" label="姓名" placeholder="请输入姓名" ><u-input v-model="form.name" /></u-form-item>
				<u-form-item label-width="150" label="手机号"  placeholder="请输入手机号"><u-input v-model="form.phone" /></u-form-item>
				<u-form-item label-width="150" label="登录账号"  placeholder="请输入账号"><u-input v-model="form.userName" /></u-form-item>
			</u-form>
		</view>
		<view class="" style="margin-top: 100rpx;">
			<u-button type="primary" style="" @click="finsh">确认</u-button>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					name: '',
					phone: '',
					userName: ''
				},
				id:''
			}
		},
		onLoad(e) {
			if(e.id){
				this.id = e.id
				this.getWaiter()
			}
			
		},
		methods: {
			//获取用户信息
			getWaiter(){
				this.$u.get('life/shop/waiter/info/'+ this.id, {
				}).then(res => {
					console.log("我是修改服务人员信息");
					console.log(res)
					this.form.name = res.data.name
					this.form.phone = res.data.phone
					this.form.userName = res.data.userName
					this.$set(this.form,'id',this.id)
				}).catch(() => {
					this.$refs.uToast.show({
						title: "请求失败",
						type: 'error',
					})
				})
			},
			finsh() {
				if(this.id){
					this.$u.put('life/shop/waiter/update', this.form).then(res => {
						console.log("我是修改服务人员");
						if(res.success){
							this.$refs.uToast.show({
								title: res.msg,
								type: 'success',
							})
							setTimeout(()=>{
								uni.navigateBack({
									delta:2
								})
							},1000)
							
						}else{
							this.$refs.uToast.show({
								title: res.msg,
								type: 'warning',
							})
						}
						console.log(res)
					}).catch(() => {
						this.$refs.uToast.show({
							title: "添加失败",
							type: 'error',
						})
					})
				}else{
					this.$u.post('life/shop/waiter/save', this.form).then(res => {
						console.log("我是添加服务人员");
						if(res.success){
							this.$refs.uToast.show({
								title: res.msg,
								type: 'success',
							})
							setTimeout(()=>{
								uni.navigateBack({
									delta:2
								})
							},1000)
						}else{
							this.$refs.uToast.show({
								title: res.msg,
								type: 'warning',
							})
						}
						console.log(res)
					}).catch(() => {
						this.$refs.uToast.show({
							title: "添加失败",
							type: 'error',
						})
					})
				}
				
			}
		}
	}
</script>

<style>

</style>